Uec3.actionOperationModule = Ext.extend(Ext.app.Module, {
    id: 'action_operation',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
    initPanel:function(params) {
   	var ajax=Uec3.App.Uec3Ajax;
   	var module=this;
    var form=new Ext.FormPanel({
  		  height:400,
	      layout:'form',
	      border:true,
	      labelWidth:60,
	      layoutConfig: 
	         {     
	           padding:'5 5 5 5',
			   align:'middle' 
	      }, 
		items:[
			{
				xtype:'hidden',
				name : 'id'
			},
			{
				xtype:'hidden',
				name : 'permissionId'
			},
			{
				fieldLabel : '动作名称',
				name : 'actionName',
				xtype:'textfield',
				width : 300
			},{
				fieldLabel : '方法名称',
				name : 'methodName',
				xtype:'textfield',
				width : 300
			},{
            layout:"hbox",
            border:false,
            layoutConfig: {     
	           padding:'100 0 0 0',
			   align:'middle',
			   pack:'center'
	      	},
	      	items:[	            
	      	new Ext.Button({
            	text:"保存",
            	width:60,
            	iconCls:'icon-save',
            	handler:function(){ 
            		var tree=module.getObjByKey("tree");
            		var window=module.getObjByKey("win");
					var curNode=tree.getSelectionModel().getSelectedNode();
					if(curNode){
						if(curNode.leaf==false){
							Ext.Msg.alert("信息",'请先选择叶子节点权限');
							return;
						}else{
							form.getForm().findField("permissionId").setValue(curNode.attributes.permission.id);
						}
					}else{
						Ext.Msg.alert("信息",'请先选中权限');
						return;
					}
					var actionJson=Ext.encode(encodeFilte(form.getForm().getValues()));
					ajax.request({
		 				url:Uec3.App.Constants.homeUrl+'/action/base!save.do',
		 				params:{actionJson:actionJson},
		 				success:function(response,options){
			 				var result = Ext.decode(response.responseText);
			 				if(result.success=="OK"){
			 					Ext.Msg.alert("信息","保存成功");
			 					window.hide();
			 				}else{
			 					Ext.Msg.alert("信息",result.success);
			 					window.hide();
			 				}
		 				}
					});
            	}
            }),
            new Ext.Button({
            	text:'关闭',
            	width:60,
            	iconCls:'icon-close',
            	handler:function(){
            		var window=module.getObjByKey("win");
            		window.hide();
            	}
            })
            ]
	}]
    });
    if(params&&params.id){
    	form.getForm().load({
    		url:Uec3.App.Constants.homeUrl+'/action/getActionById.do',
	   		params:{id:params.id},
	   		success:function(form,action){
	   			if(action.result.success=="OK"){
		   			var actionobj=action.result.data
		   			var permissionModule=Uec3.App.getModule('permission_operation')
		   			var tree=permissionModule.getObjByKey("tree");
					tree.expandAll();
	   			}
	   		}
    	});
    }
	module.objsCollection.add("form",form);
	},
	initEvent:function(params){
		var module=this;
		var win=module.getObjByKey("win");
		var tree=module.getObjByKey("tree");

	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params&&params.winId){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = Uec3.App.getDesktop();   
      var win = desktop.getWindowByUecId(windowId);
      if(!win){ 
      	 var module=this;
      	 module.initPanel(params);
      	 /* var permissionModule=new Uec3.permissionOperationModule();
      	 permissionModule.initPanel();*/
      	 /*Ext.App.launchWindowByParam('permission_operation',{noCreate:true});
      	 permissionModule.initPanel();*/
      	 //var tree=permissionModule.getObjByKey('tree');
      	 //Ext.util.Observable.createCallback()
      	 var permissionModule=desktop.getWindowComponent('permission_operation','initPanel');
      	 var tree=permissionModule.getObjByKey('tree');
         win = desktop.createWindow({
            uecId: windowId,
            width: 600,
            height: 400,
            title:'action管理',
            iconCls: 'acc-icon-saleInvoice',
            shim: false,
            moduleObj:module,
            constrainHeader: true,
            maximizable: true,
            layout: "hbox", 
            items:[module.getObjByKey("form"),tree],
            listeners:{
            	/*'resize':function(win,width,height){
            		var treePanel=this.items.get(0).items.first();
            		//var treePanel=this.items.get(0).items.last();
            		var winMinWidth=600;
            		var winMinHeight=400;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);           			
            		}else{
            			 treePanel.setWidth(width-15);
         				 treePanel.setHeight(height-30);
            		}
            	}*/
            	
            }
         });
         module.objsCollection.add("win",win);
         module.objsCollection.add("tree",tree);
         module.initEvent(params);
      } 
      win.show();
   }
});
